package handlers

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

func DynamicUrlHandler(c *gin.Context) {
	name := c.Param("name")
	action := c.Param("action")
	message := name + " is " + action
	c.String(http.StatusOK, message)
}

func GeneralGetHandler(c *gin.Context) {
	firstName := c.DefaultQuery("firstname", "Guest")
	lastName := c.Query("lastname") // 是 c.Request.URL.Query().Get("lastname") 的简写
	c.String(http.StatusOK, "Hello %s %s", firstName, lastName)
}

func GeneralPostHandler(c *gin.Context) {
	message := c.PostForm("message")
	nick := c.DefaultPostForm("nick", "anonymous") // 此方法可以设置默认值
	c.JSON(200, gin.H{
		"status":  "posted",
		"message": message,
		"nick":    nick,
	})
}
